import {request,service } from "@/utils/reuqest";
import type {
    AddIndustry, Datum,
    EnterpriseDetail,
    EnterpriseListData,
    EnterpriseListParams,
    Industry, Rent,
    UploadUserFile
} from "@/types/enterprise";

/**
 * 获取企业列表
 */
export const getEnterpriseListAPI = (params: EnterpriseListParams) => {
    return request<EnterpriseListData>('/park/enterprise','GET',params)
}
/**
 * 获取行业列表
 */
export const getIndustryListAPI = () => {
    return request<Industry[]>('/park/industry')
}
/**
 * 上传合同
 * @returns
 */
export const uploadAPI = (data: FormData) =>{
    return request<UploadUserFile>('/upload', 'POST', data)
}
/**
 * 创建公司
 * @param {*} data
 * @returns
 */
export const createEnterpriseAPI = (data: AddIndustry) =>{
    return request('/park/enterprise', 'POST', data)
}

/**
 * 获取企业详情
 */
export const getEnterpriseDetailAPI = (id: string) => {
    return request<EnterpriseDetail>(`/park/enterprise/${id}`)
}
/**
 * 编辑企业
 */
export const editEnterpriseAPI = (data: AddIndustry) =>{
    return request('/park/enterprise', 'PUT', data)
}
/**
 * 删除企业
 * @param {*} id
 * @returns
 */
export const delEnterpriseAPI = (id: string) => {
    return request(`/park/enterprise/${id}`, 'DELETE')
}
/**
 * 获取空置中楼宇列表（未租赁）
 * @param {*} id
 * @returns
 */
export const getRentBuildListAPI = () => {
    return request<{id: string, name: string}[]>('/park/rent/building')
}
/**
 * 给当前企业添加合同
 * @param {*} data
 * @returns
 */
export const  createRentAPI = (data: Rent) => {
    return request('/park/enterprise/rent', 'POST', data)
}
/**
 * 获取企业下合同列表
 * @param {*} id
 * @returns
 */
export const getRentListAPI = (id: string) => {
    return request<Datum[]>(`/park/enterprise/rent/${id}`)
}
/**
 * 退租
 * @param {合同id} rentId
 * @returns
 */
export const outRentAPI = (rentId: string)=> {
    return request(`/park/enterprise/rent/${rentId}`, 'PUT')
}
/**
 * 删除企业合同
 */
export const delRentAPI = (rentId: string) => {
    return request(`/park/enterprise/rent/${rentId}`, 'DELETE')
}
/**
 * 下载合同文件
 */
export const downloadContract = (id: string) => {
    return service({
        url: `/download/${id}`,
        responseType: 'blob'
    })
}